package day08.TressSet.BiJiao;

import java.util.Comparator;
import java.util.TreeSet;

public class Text {
    public static void main(String[] args) {
        TreeSet<Student> ts = new TreeSet<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                int result = o1.getAge() - o2.getAge();
                result = result == 0 ?
                        o1.getName().compareTo(o2.getName()) : result;
                return result;
            }
        });
        Student t1 = new Student("zhangsan", 23);
        Student t2 = new Student("lisi", 22);
        Student t3 = new Student("wangwu", 24);
        Student t4 = new Student("zhaoliu", 24);
        //把老师添加到集合
        ts.add(t1);
        ts.add(t2);
        ts.add(t3);
        ts.add(t4);
        for (Student t : ts) {
            System.out.println(t);
        }
    }
}
